/* GUI CONVERTED from porvisa.p (converter v1.76) Wed Jul  3 22:06:37 2002 */
/* porvisa.p - PURCHASE ORDER RETURN TO SUPPLIER ISSUE                  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.16.3.18 $                                                          */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 6.0     LAST MODIFIED: 08/08/90    BY: RAM *D030*          */
/* REVISION: 6.0     LAST MODIFIED: 10/29/90    BY: WUG *D151*          */
/* REVISION: 6.0     LAST MODIFIED: 12/17/90    BY: WUG *D227*          */
/* REVISION: 6.0     LAST MODIFIED: 01/15/91    BY: RAM *D300*          */
/* REVISION: 6.0     LAST MODIFIED: 03/27/91    BY: RAM *D462*          */
/* REVISION: 6.0     LAST MODIFIED: 04/11/91    BY: RAM *D518*          */
/* REVISION: 6.0     LAST MODIFIED: 05/10/91    BY: RAM *D641*          */
/* REVISION: 6.0     LAST MODIFIED: 05/30/91    BY: RAM *D666*          */
/* REVISION: 6.0     LAST MODIFIED: 06/25/91    BY: RAM *D676*          */
/* REVISION: 6.0     LAST MODIFIED: 07/16/91    BY: RAM *D777*          */
/* REVISION: 6.0     LAST MODIFIED: 08/29/91    BY: pma *D829*          */
/* REVISION: 6.0     LAST MODIFIED: 09/12/91    BY: WUG *D858*          */
/* REVISION: 6.0     LAST MODIFIED: 09/20/91    BY: RAM *D871*          */
/* REVISION: 6.0     LAST MODIFIED: 10/03/91    BY: alb *D887*          */
/* REVISION: 6.0     LAST MODIFIED: 11/08/91    BY: RAM *D923*          */
/* REVISION: 7.0     LAST MODIFIED: 12/02/91    BY: pma *F003*          */
/* REVISION: 7.0     LAST MODIFIED: 12/09/91    BY: RAM *F070*          */
/* REVISION: 7.0     LAST MODIFIED: 02/12/92    BY: pma *F190*          */
/* REVISION: 7.0     LAST MODIFIED: 03/25/92    BY: pma *F089*          */
/* REVISION: 7.3     LAST MODIFIED: 09/27/92    BY: jcd *G247*          */
/* REVISION: 7.3     LAST MODIFIED: 11/09/92    BY: afs *G303*          */
/* REVISION: 7.3     LAST MODIFIED: 12/14/92    BY: tjs *G443*          */
/* REVISION: 7.3     LAST MODIFIED: 02/25/93    BY: tjs *G751*          */
/* REVISION: 7.3     LAST MODIFIED: 09/14/93    BY: tjs *GE59*          */
/* REVISION: 7.3     LAST MODIFIED: 11/03/93    BY: afs *H220*          */
/* REVISION: 7.4     LAST MODIFIED: 07/19/94    BY: dpm *FP45*          */
/* REVISION: 7.4     LAST MODIFIED: 09/11/94    BY: rmh *GM16*          */
/* REVISION: 7.4     LAST MODIFIED: 10/27/94    BY: ljm *GN62*          */
/* REVISION: 8.5     LAST MODIFIED: 11/18/94    BY: taf *J038*          */
/* REVISION: 7.4     LAST MODIFIED: 11/19/94    BY: bcm *GO37*          */
/* REVISION: 8.5     LAST MODIFIED: 11/28/94    BY: mwd *J034*          */
/* REVISION: 8.5     LAST MODIFIED: 12/19/94    BY: ktn *J041*          */
/* REVISION: 8.5     LAST MODIFIED: 08/21/95    BY: kxn *J066*          */
/* REVISION: 7.4     LAST MODIFIED: 10/17/95    BY: jym *F0TC*          */
/* REVISION: 8.5     LAST MODIFIED: 05/14/96    BY: rxm *G1SL*          */
/* REVISION: 8.5     LAST MODIFIED: 07/10/96    BY: *G1Z8* Ajit Deodhar */
/* REVISION: 8.5     LAST MODIFIED: 07/30/96    BY: *G2B5* suresh Nayak */
/* REVISION: 8.5     LAST MODIFIED: 09/09/96    BY: *G2DV* Aruna P.Patil*/
/* REVISION: 8.5     LAST MODIFIED: 04/16/97    BY: *G2M2* Suresh Nayak */
/* REVISION: 8.5     LAST MODIFIED: 08/14/97    BY: *H1B4* Manmohan K.Pardesi */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98    BY: *L007* A. Rahane     */
/* REVISION: 8.6E    LAST MODIFIED: 05/20/98    BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E    LAST MODIFIED: 06/12/98    BY: *J2N3* Niranjan R.   */
/* REVISION: 8.6E    LAST MODIFIED: 06/26/98    BY: *J2MG* Samir Bavkar  */
/* REVISION: 8.6E    LAST MODIFIED: 08/28/98    BY: *J2WJ* Ajit Deodhar  */
/* REVISION: 9.1     LAST MODIFIED: 06/26/99    BY: *J3H8* Sachin Shinde */
/* REVISION: 9.1     LAST MODIFIED: 06/30/99    BY: *N00R* Reetu Kapoor  */
/* REVISION: 9.1     LAST MODIFIED: 08/10/99    BY: *N01K* J. Fernando   */
/* REVISION: 9.1     LAST MODIFIED: 09/16/99    BY: *J3LC* Anup Pereira  */
/* REVISION: 9.1     LAST MODIFIED: 10/25/99    BY: *N002* Steve Nugent  */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1     LAST MODIFIED: 07/11/00    BY: *M0PQ* Falguni Dalal    */
/* REVISION: 9.1     LAST MODIFIED: 09/05/00    BY: *N0RF* Mark Brown       */
/* REVISION: 9.1     LAST MODIFIED: 09/06/00    BY: *M0RJ* Kaustubh K.      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* Old ECO marker removed, but no ECO header exists *J04D*                  */
/* Revision: 1.16.3.16   BY: Hualin Zhong   DATE: 05/03/01   ECO: *N0Y8*    */
/* Revision: 1.16.3.17   BY: Hualin Zhong   DATE: 05/07/01   ECO: *N0YC*    */
/* $Revision: 1.16.3.18 $           BY: Nishit V       DATE: 07/03/02   ECO: *N1MW*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*!
porvisa.p - ITEM ENTRY FOR PO RETURNS
*/

/*!
CHANGES MADE IN THIS PROGRAM MUST ALSO BE MADE TO POPORCA.P
*/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE porvisa_p_1 "Multi Entry"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_2 "Packing Qty"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_4 "Issue"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_5 "Net Received"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_6 "Loc"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_7 "Lot/Serial"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_8 "Cmmts"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_9 "Comments"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_10 "RTV Nbr"
/* MaxLen: Comment: */

&SCOPED-DEFINE porvisa_p_11 "Return Qty"
/* MaxLen: Comment: */


/* ********** End Translatable Strings Definitions ********* */

{porcdef.i}
/* VARIABLE DEFINITION FOR GL CALENDAR VALIDATION */
{gpglefdf.i}

/* NEW SHARED VARIABLES, BUFFERS AND FRAMES */
define new shared variable cline as character.
define new shared variable issue_or_receipt as character.
define new shared variable line like pod_line format ">>>".
define new shared variable lotserial_control as character.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable multi_entry like mfc_logical
   label {&porvisa_p_1} no-undo.
define new shared variable podtype like pod_type.
define new shared variable rct_site like pod_site.
define new shared variable total_lotserial_qty like pod_qty_chg.
define new shared variable trans_um like pt_um.
define new shared variable trans_conv like sod_um_conv.
define new shared variable undo_all like mfc_logical.

/* SHARED VARIABLES, BUFFERS AND FRAMES */
define shared variable receivernbr like prh_receiver label {&porvisa_p_10}.
define shared variable qopen like pod_qty_rcvd label {&porvisa_p_5}.
define shared variable vendlot like tr_vend_lot no-undo.
define shared variable h_wiplottrace_procs as handle        no-undo.
define shared variable h_wiplottrace_funcs as handle        no-undo.

define shared frame b.

/* LOCAL VARIABLES, BUFFERS AND FRAMES */
define variable cmmt_yn like mfc_logical label {&porvisa_p_9} no-undo.
define variable due like pod_due.
define variable dwn as integer.
define variable yn like mfc_logical.
define variable i as integer.
define variable del-yn like mfc_logical initial no.
define variable serial_control like mfc_logical initial no.
define variable qty_left like tr_qty_chg.
define variable cont like mfc_logical initial yes.
define variable first_down as integer initial 0.
define variable reset_um like mfc_logical initial no.
define variable conv_to_pod_um like pod_um_conv.
define variable packing_qty like pod_ps_chg
   label {&porvisa_p_2} no-undo.
define variable total_returned like pod_qty_rtnd no-undo.
define variable overage_qty like pod_qty_rtnd no-undo.
define variable return_um like pod_rum no-undo.
define variable lineid_list as character no-undo.
define variable overissue_ok like mfc_logical no-undo.
define variable undotran like mfc_logical no-undo.
define variable ponbr like pod_nbr no-undo.
define variable poline like pod_line no-undo.
define variable lotnext like pod_lot_next no-undo.
define variable lotprcpt like pod_lot_rcpt no-undo.
define variable l_reset_pod like mfc_logical no-undo.
define variable l_chkum     like mfc_logical no-undo.

define        variable rejected            like mfc_logical no-undo.
define        variable lotserials_req      like mfc_logical no-undo.
define        variable mess_desc           as character     no-undo.
define        variable leave_loop          like mfc_logical
   initial no       no-undo.
define        variable l_remove_srwkfl     like mfc_logical no-undo.
define buffer poddet for pod_det.
{wlfnc.i} /* FUNCTION FORWARD DECLARATIONS */
{wlcon.i} /* CONSTANTS DEFINITIONS */

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
po_nbr         colon 15
   po_vend
   po_stat
   receivernbr    to 78
 SKIP(.4)  /*GUI*/
with frame b side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

FORM /*GUI*/ 
with frame c title color normal
   (getFrameTitle("PURCHASE_ORDER_LINE_ITEMS",36))
   6 down width 80 THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
line           colon 14
   return_um      colon 34
   site           colon 55
   location       colon 69 no-attr-space label {&porvisa_p_6}
   lotserial_qty  colon 14
   wolot          colon 34
   lotserial      colon 55
   packing_qty    colon 14
   woop           colon 34
   lotref         colon 55 format "x(8)"
   pod_part       colon 14
   multi_entry    colon 55
   pod_vpart      colon 14
   pod_reason     colon 55
   cmmt_yn        colon 71 label {&porvisa_p_8}
 SKIP(.4)  /*GUI*/
with frame d side-labels attr-space width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-d-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame d = F-d-title.
 RECT-FRAME-LABEL:HIDDEN in frame d = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame d =
  FRAME d:HEIGHT-PIXELS - RECT-FRAME:Y in frame d - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME d = FRAME d:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

issue_or_receipt = getTermLabel("ISSUE", 7).

if is_wiplottrace_enabled() then
   run init_poline_bkfl_input_output.

find first poc_ctrl no-lock.
find po_mstr where recid(po_mstr) = po_recno.

line = 1.
proceed = no.

edit-loop:

repeat on endkey undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


   display
      po_nbr
      po_vend
      po_stat
      receivernbr
   with frame b.

   lineloop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


      clear frame c all no-pause.
      clear frame d all no-pause.
      /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

      view frame b.
      view frame c.
      view frame d.

      for each pod_det no-lock where pod_nbr = po_nbr
            and pod_line >= line and pod_qty_rtnd < pod_qty_rcvd
            use-index pod_nbrln by pod_line:

         find si_mstr where si_site = pod_site no-lock.
         if si_db <> global_db then next.

         find pt_mstr where pt_part = pod_part no-lock no-error.

         qopen = pod_qty_rcvd - pod_qty_rtnd.
         display
            pod_line
                 space(.5)   
            pod_part
                 space(.5)   
            pt_um when (available pt_mstr)
                 space(.5)   
            qopen
                 space(.5)   
            pod_um
                 view-as fill-in size 3.5 by 1 space(.5)   
            pod_qty_chg label {&porvisa_p_11}
                 space(.5)   
            pod_rum
                 view-as fill-in size 3.5 by 1 space(.5)   
            pod_project
                 space(.5)   
            pod_due_date
                 space(.5)   
            pod_type
         with frame c.
         if frame-line(c) = frame-down(c) then leave.
         down 1 with frame c.

      end.

      line = 0.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         update line with frame d
         editing:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp01.i pod_det line pod_line pod_nbr po_nbr pod_nbrln}
            if recno <> ? then
            np-poddet:
            do:
               find si_mstr where si_site = pod_site no-lock no-error.
               if si_db <> global_db then leave np-poddet.
               line = pod_line.
               cmmt_yn = yes.
               display
                  line
                  pod_qty_chg @ lotserial_qty
                  pod_ps_chg @ packing_qty
                  pod_part
                  pod_vpart
                  pod_rum @ return_um
                  pod_wo_lot @ wolot
                  pod_op @ woop
                  pod_reason
                  cmmt_yn
               with frame d.
            end.
         end. /* end update */

         if line = 0 then leave lineloop.

         find pod_det where pod_nbr = po_nbr
            and pod_line = line no-error.
         if not available pod_det then do:
            {pxmsg.i &MSGNUM=45 &ERRORLEVEL=3} /* Line item does not exist */
            undo, retry.
         end.
         else do:  /* Validate that line is for this database */
            find si_mstr where si_site = pod_site no-lock.
            if si_db <> global_db then do:
               {pxmsg.i &MSGNUM=5421 &ERRORLEVEL=3}
               /* SITE NOT ASSIGNED TO THIS DB */
               undo, retry.
            end.
            ponbr = pod_nbr.
         end.

         /*  PICK UP CURRENTLY EFFECTIVE CUM ORDER */
         {gprun.i ""poporca5.p""
            "(input pod_nbr, input pod_line, input eff_date)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if pod_status = "c" or pod_status = "x" then do:
            {pxmsg.i &MSGNUM=336 &ERRORLEVEL=2
                     &MSGARG1=getTermLabel(""REOPENED"",11)}
            /* PO LINE IS CLOSED OR CANCELLED */
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

      assign
         packing_qty = pod_ps_chg
         wolot = pod_wo_lot
         woop = pod_op
         return_um = pod_rum
         cmmt_yn = yes.
      display
         line
         packing_qty
         pod_part
         pod_vpart
         return_um
         wolot
         woop
         pod_site @ site
         pod_reason
         cmmt_yn
      with frame d.

      if available si_mstr then do:
         {gprun.i ""gpsiver.p""
            "(input si_site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
      else do:
         {gprun.i ""gpsiver.p""
            "(input pod_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
      if return_int = 0 then do:
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /* USER DOES NOT HAVE ACCESS TO THIS SITE */
         pause.
         undo, retry.
      end.

      /* Initialize input variables, check for open vouchers. */

      pod_recno = recid(pod_det).
      {gprun.i ""poporca3.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      assign
         lotnext =  lotserial
         lotprcpt = no
         poline = line
         vendlot = "".

      locloop:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         ststatus = stline[3].
         status input ststatus.

         find first sr_wkfl where sr_userid = mfguser
            and sr_lineid = cline no-lock no-error.

         i = 0.
         multi_entry = no.
         for each sr_wkfl no-lock where sr_userid = mfguser
               and sr_lineid = cline:
            i = i + 1.
            if i > 1 then do:
               multi_entry = yes.
               leave.
            end.
         end.

         display
            lotserial_qty
            packing_qty
            return_um
            wolot
            woop
            site
            location
            lotserial
            lotref
            multi_entry
            pod_reason
            cmmt_yn
         with frame d.

         set
            lotserial_qty
            packing_qty
            return_um
            wolot
            woop
            site         when (not multi_entry and not
                         (is_wiplottrace_enabled() and pod_type = "s"))
            location     when (not multi_entry and not
                         (is_wiplottrace_enabled() and pod_type = "s"))
            lotserial    when (not multi_entry and not
                         (is_wiplottrace_enabled() and pod_type = "s"))
            lotref       when (not multi_entry and not
                         (is_wiplottrace_enabled() and pod_type = "s"))
            multi_entry  when (not multi_entry and not
                         (is_wiplottrace_enabled() and pod_type = "s"))
            pod_reason
            cmmt_yn
         with frame d
         editing:
            assign
               global_site = input site
               global_loc = input location
               global_lot = input lotserial.
            readkey.
            apply lastkey.
         end.

         assign
            l_chkum = no
            conv_to_pod_um = 1.

         if available pt_mstr and return_um = pt_um then
         assign
            l_chkum = yes
            conv_to_pod_um = 1 / pod_um_conv.
         else
            if return_um <> pod_um then do:
            /*LOOK FOR RETURN UM TO LINE ITEM UM CONV*/
            {gprun.i ""gpumcnv.p""
               "(input return_um, input pod_um, input pod_part,
                 output conv_to_pod_um)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if conv_to_pod_um = ? then do:
               /*NOT FOUND, LOOK FOR RETURN UM TO STOCKING UM CONV*/
               find pt_mstr where pt_part = pod_part no-lock no-error.
               if available pt_mstr then do:
                  {gprun.i ""gpumcnv.p""
                     "(input return_um, input pt_um, input pod_part,
                       output conv_to_pod_um)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if conv_to_pod_um <> ? then
                     /*CHG RTN-TO-VNDR-UM-CONV TO RTN-FROM-LINEITEM-CONV*/
                     conv_to_pod_um =  conv_to_pod_um / pod_um_conv.
               end.
            end.
         end. /* if return_um <> pod_um */

         if conv_to_pod_um = ? then do:
            {pxmsg.i &MSGNUM=33 &ERRORLEVEL=3}
            /* No unit of measure conversion exists */
            next-prompt return_um with frame d.
            undo, retry.
         end.

         {gprun.i ""gpsiver.p""
            "(input (input site), input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            /* USER DOES NOT HAVE ACCESS TO THIS SITE */
            next-prompt site with frame d.
            undo, retry.
         end.

         /* VERIFY OPEN GL PERIOD FOR LINE ITEM SITE/ENTITY */

         for first si_mstr
               fields ( si_db si_entity si_site )
               where si_site = site no-lock:
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR FIRST SI_MSTR */

         if available si_mstr then do:
            /* CHECK GL EFFECTIVE DATE */
            {gpglef02.i &module = ""IC""
               &entity = si_entity
               &date   = eff_date
               &prompt = "site"
               &frame  = "d"
               &loop   = "locloop"}
         end. /* IF AVAILABLE SI_MSTR */

         rct_site = pod_site.
         if pod_type = "S" then do:
            undo_all = false.
            pod_recno = recid(pod_det).
            /* SUBCONTRACT WORKORDER UPDATE */
            {gprun.i ""poporca2.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

            if undo_all then do:
               next-prompt wolot with frame d.
               undo, retry.
            end.

         end. /* pod_type = "S" */

         i = 0.
         for each sr_wkfl no-lock where sr_userid = mfguser
               and sr_lineid = cline:
            i = i + 1.
            if i > 1 then do:
               multi_entry = yes.
               leave.
            end.
         end.

         total_lotserial_qty = pod_qty_chg.
         trans_um = return_um.

         if l_chkum then
            trans_conv = 1.
         else
            trans_conv = conv_to_pod_um * pod_um_conv.

         if multi_entry then do:

            /* THIS PATCH INSURES THAT AT LEAST ONE sr_wkfl ENTRY IS
            PASSED  TO icsrup2.p ( MULTI ENTRY  MODE HANDLER ) EVEN IF
            RECEIVE ALL IS SET TO NO; SO AS TO BRING CONSISTENCY WITH
            RECEIVE ALL SET TO YES.
            */

            /* CREATE BEGINS */

            find pt_mstr where pt_part = pod_part no-lock no-error.
            if not available pt_mstr         or
                  (available pt_mstr         and
                             pt_lot_ser = "" and
                             pod_type <> "s")
            then do:

               find first sr_wkfl where sr_userid = mfguser
                  and sr_lineid = cline no-lock no-error.
               if not available sr_wkfl then do:
                  create sr_wkfl.
                  assign
                     sr_userid = mfguser
                     sr_lineid = cline
                     sr_site = site
                     sr_loc = location
                     sr_lotser = lotserial
                     sr_ref = lotref
                     sr_qty = lotserial_qty.
               end.

            end.

            /* CREATE ENDS */

            find first sr_wkfl where sr_userid = mfguser
               and sr_lineid = cline exclusive-lock no-error.
            if lotserial_qty = 0 then do:
               if available sr_wkfl then do:
                  total_lotserial_qty = total_lotserial_qty - sr_qty.
                  delete sr_wkfl.
               end.
            end.
            else do:
               if available sr_wkfl then do:
                  find sr_wkfl where sr_userid = mfguser and
                     sr_lineid = cline exclusive-lock no-error.
                  if not ambiguous sr_wkfl then
                  assign
                     sr_site = site
                     sr_loc = location
                     sr_lotser = lotserial
                     sr_ref = lotref
                     sr_qty = lotserial_qty.
               end.    /* avail sr_wkfl */

            end.

            if i >= 1 then
            assign
               location = ""
               lotserial = ""
               lotref = "".

            podtype = pod_type.

            total_lotserial_qty = 0.
            for each sr_wkfl where sr_userid = mfguser and
                  sr_lineid = cline no-lock:
               total_lotserial_qty = total_lotserial_qty + sr_qty.
            end.

            {gprun.i ""icsrup2.p"" "(input rct_site,
                          input ponbr,
                          input poline,
                          input-output lotnext,
                          input lotprcpt,
                          input-output vendlot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            assign pod__qad04[1] = vendlot.
         end.
         else do:
            if pod_type = "" then do:

               /* CHANGED TENTH INPUT PARAMETER STRING (POD_LINE) TO "" SO  */
               /* THAT MULTIPLE LINES OF SAME LOT CAN BE RETURNED           */
               {gprun.i ""icedit.p"" "(""ISS-PRV"",
                        site,
                        location,
                        global_part,
                        lotserial,
                        lotref,
                        lotserial_qty * trans_conv,
                        trans_um,
                        pod_nbr,
                        """",
                        output yn)"
                  }
/*GUI*/ if global-beam-me-up then undo, leave.

               if yn then undo locloop, retry.

               if pod_site <> site then do:
                  /* Set qty to zero for transfer transaction, since */

                  {gprun.i ""icedit4.p"" "(input transtype,
                               input rct_site,
                               input site,
                               input pt_loc,
                               input location,
                               input global_part,
                               input lotserial,
                               input lotref,
                               input lotserial_qty *
                             trans_conv,
                               input trans_um,
                               input """",
                               input """",
                               output yn)"
                     }
/*GUI*/ if global-beam-me-up then undo, leave.

                  if yn then undo locloop, retry.
               end.
            end.
            else do:
               if pod_type <> "S" then do:
                  {icedit1.i
                     &site=site
                     &part=global_part
                     &lotserial=lotserial
                     &quantity="lotserial_qty * trans_conv"
                     &um=trans_um
                     &transtype=transtype
                     }
               end.   /* pod_type <> "S" */
            end.

            find first sr_wkfl where sr_userid = mfguser
               and sr_lineid = cline exclusive-lock no-error.
            if lotserial_qty = 0 then do:
               if available sr_wkfl then do:
                  total_lotserial_qty = total_lotserial_qty - sr_qty.
                  delete sr_wkfl.
               end.
            end.
            else do:
               if available sr_wkfl then
                  assign
                     total_lotserial_qty = total_lotserial_qty
                                         - sr_qty
                                         + lotserial_qty
                     sr_site = site
                     sr_loc = location
                     sr_lotser = lotserial
                     sr_ref = lotref
                     sr_qty = lotserial_qty.
               else do:
                  create sr_wkfl.
                  assign
                     sr_userid = mfguser
                     sr_lineid = cline
                     sr_site = site
                     sr_loc = location
                     sr_lotser = lotserial
                     sr_ref = lotref
                     sr_qty = lotserial_qty
                     total_lotserial_qty = total_lotserial_qty
                                         + lotserial_qty.

                  if recid(sr_wkfl) = -1 then .
               end. /* not avail sr_wkfl */
            end. /* lotserial_qty <> 0 */

            if porec or is-return then do:
               /* CHECK FOR SINGLE ITEM / SINGLE LOT/SERIAL LOCATION */
               find loc_mstr where loc_site = site
                  and loc_loc = location no-lock no-error.

               if available loc_mstr and loc_single = yes then do:
                  {gploc02.i pod_det pod_nbr pod_line pod_part}

                  if error_flag = 0 and loc__qad01 = yes then do:
                     /* CHECK PRIOR RECEIPT TRANSACTIONS (ld_det's) FOR
                     DIFFERENT ITEMS OR LOT/SERIALS IN SAME LOCATION */
                     {gprun.i ""gploc01.p""
                        "(site,
                          location,
                          pod_part,
                          lotserial,
                          lotref,
                          loc__qad01,
                          output error_flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                     if error_flag <> 0
                        /* ADJUSTING QTY ON A PREVIOUS VIOLATION (CREATED
                        BEFORE THIS PATCH) OF SINGLE ITEM/LOT/SERIAL
                        LOCATION ALLOWED; CREATING ANOTHER VIOLATION
                        DISALLOWED.
                        */
                        and can-find(ld_det where ld_site = site
                        and ld_loc = location and ld_part = pod_part
                        and ld_lot = lotserial and ld_ref = lotref) then
                        error_flag = 0.
                  end. /* error_flag = 0 and loc__qad01 = yes */

                  if error_flag <> 0 then do:
                     {pxmsg.i &MSGNUM=596 &ERRORLEVEL=3}
                     /*TRANSACTION CONFLICTS WITH SINGLE ITEM/LOT LOC*/
                     undo locloop, retry.
                  end.
               end. /* avail loc_mstr and loc_single = yes */
            end. /* porec or is-return */
         end. /* not multi_entry */

         if pod_type = "" then do:
            lineid_list = "".

            for each poddet where poddet.pod_nbr = pod_det.pod_nbr
                              and poddet.pod_part = pod_det.pod_part
                              and poddet.pod_type = "" no-lock:
               assign lineid_list = lineid_list +
                  trim(string(poddet.pod_line)) + ",".
            end. /* FOR EACH PODDET */

            lineid_list = substring(lineid_list,1,
               ((r-index(lineid_list,",") - 1))).

            if lotserial_qty > 0 then do:

               {gprun.i ""icoviss2.p"" "(input pod_det.pod_part,
                                         input pod_det.pod_nbr,
                                         input lineid_list,
                                         input pod_det.pod_line,
                                         input conv_to_pod_um,
                                         input l_chkum,
                                         output undotran,
                                         output overissue_ok)"
                  }
/*GUI*/ if global-beam-me-up then undo, leave.

               if undotran then undo locloop, retry locloop.
               if not overissue_ok then undo locloop, retry locloop.
            end. /* IF LOTSERIAL_QTY > 0 THEN */
         end. /* IF pod_type = "" */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      pod_qty_chg = total_lotserial_qty.

      /* CHECK OPERATION QUEUE QTIES*/
      {gprun.i ""poporca6.p""
         "(input ""return"", input pod_nbr, input wolot, input woop,
           input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if l_chkum then
         total_returned = pod_qty_rtnd
                        + (total_lotserial_qty / pod_um_conv).
      else
         total_returned = pod_qty_rtnd
                        + (total_lotserial_qty * conv_to_pod_um).
      assign
         pod_rum_conv = conv_to_pod_um
         pod_rum = return_um
         pod_ps_chg = packing_qty.

      if pod_type = 's' then do:
         run check_and_get_wip_lots
            (input recid(pod_det),
            input wolot, input woop,
            input move,
            output leave_loop).

         if leave_loop then undo lineloop, retry lineloop.
      end.

      if (pod_qty_rcvd >= 0 and ( total_returned < 0
         or total_returned  > pod_qty_rcvd))
         or (pod_qty_rcvd < 0  and ( total_returned > 0
         or total_returned  < pod_qty_rcvd))
      then do:
         {pxmsg.i &MSGNUM=375 &ERRORLEVEL=3}
         /* Cannot return more than received */
         undo lineloop, retry lineloop.
      end.

      /* ADD COMMENTS, IF DESIRED */
      if cmmt_yn then do:
         hide frame b no-pause.
         hide frame c no-pause.
         hide frame d no-pause.
         cmtindx = pod_cmtindx.
         /* USE PREFIX VARIABLE = "RTV: " */

         global_ref = cmmt-prefix + " " +
                      pod_nbr + "/" + string(pod_line).
         {gprun.i ""gpcmmt01.p"" "(input ""pod_det"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

         pod_cmtindx = cmtindx.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   do on endkey undo edit-loop, leave edit-loop:
      assign
         l_reset_pod     = yes
         l_remove_srwkfl = yes
         yn              = yes.
      {pxmsg.i &MSGNUM=376 &ERRORLEVEL=1 &CONFIRM=yn}
      /* Display purchase order lines being returned? */
      l_reset_pod = no.
      if yn then do:
         hide frame c.
         hide frame d.
         for each pod_det no-lock
               where pod_nbr = po_nbr and pod_qty_chg <> 0
               use-index pod_nbrln,
               each sr_wkfl no-lock where sr_userid = mfguser
               and sr_lineid = string(pod_line) with frame f_pod width 80
               break by pod_line by pod_part by sr_site
               by sr_loc by sr_lotser by sr_ref:

            /* SET EXTERNAL LABELS */
            setFrameLabels(frame f_pod:handle).

            if first-of(sr_lotser) then do:
               display
                  pod_line
                  pod_part
                  sr_site
                  sr_loc
                  sr_lotser
                  column-label {&porvisa_p_7}.
               if sr_ref <> "" then down 1.
            end.
            display
               sr_ref format "x(8)" when (sr_ref <> "") @ sr_lotser
               sr_qty
               pod_rum.
         end.
      end.
   end.

   do on endkey undo edit-loop, leave edit-loop:
      proceed = no.
      assign
         l_reset_pod = yes
         yn = yes.

      /* Is all information correct */
      {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn}
           
      if yn = ? then
         undo edit-loop, leave edit-loop.
        

      assign
         l_remove_srwkfl = no
         l_reset_pod     = no.
      if yn then do:
         proceed = yes.
         leave.
      end.
   end.
end.

if l_reset_pod then
/* SET RECEIPT QTY TO ZERO FOR ALL PO LINES */
run p-upd-pod-det.

hide frame c no-pause.
hide frame d no-pause.

if l_remove_srwkfl then
do:
   for each sr_wkfl exclusive-lock where sr_userid = mfguser:
      delete sr_wkfl.
   end. /* FOR EACH SR_WKFL */
end. /* IF L_REMOVE_SRWKFL */

/* SET RECEIPT QTY TO ZERO FOR ALL PO LINES */
PROCEDURE p-upd-pod-det:

   for each pod_det exclusive-lock
         where pod_nbr = po_mstr.po_nbr:
      pod_qty_chg = 0.
   end. /*FOR EACH POD_DET*/

END PROCEDURE. /* PROCEDURE P-UPD-POD-DET */

/* ADDED FOLLOWING PROCEDURE TO INITIALIZE WIP LOT TRACE TEMP TABLES*/
PROCEDURE init_poline_bkfl_input_output:
   run init_poline_bkfl_input_wip_lot
      in h_wiplottrace_procs.

   run init_poline_bkfl_output_wip_lot
      in h_wiplottrace_procs.
END PROCEDURE.

/* ADDED FOLLOWING PROCEDURE TO PROCESS/VALIDATE WIP LOTS */
PROCEDURE check_and_get_wip_lots:
   define input parameter ip_pod_recid as recid no-undo.
   define input parameter ip_wo_id as character no-undo.
   define input parameter ip_wo_op as integer no-undo.
   define input parameter ip_move as logical no-undo.
   define output parameter op_undo_all as logical no-undo.

   define variable rejected as logical no-undo.

   find pod_det where recid(pod_det) = ip_pod_recid exclusive-lock.
   for first po_mstr where po_nbr = pod_nbr no-lock:
   end.

   for first wo_mstr where wo_lot = ip_wo_id
         and wo_nbr = "" no-lock:
   end.

   if not available wo_mstr then leave.

   for first wr_route
         where wr_lot = ip_wo_id and wr_op = ip_wo_op
         no-lock:
   end.

   if not available wr_route then leave.

   if not wr_milestone then do:
      {pxmsg.i &MSGNUM=560 &ERRORLEVEL=2}

      if is_wiplottrace_enabled() then do:
         if prev_milestone_operation(ip_wo_id, ip_wo_op) <> ?
            and is_operation_queue_lot_controlled
            (ip_wo_id,
            prev_milestone_operation(ip_wo_id, ip_wo_op),
            OUTPUT_QUEUE)
         then do:
            {pxmsg.i &MSGNUM=8465 &ERRORLEVEL=3}
            /* WIP LOT TRACE IS ENABLED AND OPERATION IS A
               NON-MILESTONE */
            op_undo_all = true.
            leave.
         end.
      end.
   end.

   {gprun.i ""recrtcl.p""
      "(input wo_lot, input ip_wo_op, input yes,
        input  - pod_qty_chg * pod_um_conv * pod_rum_conv,
        input eff_date, input yes, input wr_wkctr,
        output rejected, output lotserials_req)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   if rejected then do:
      assign
         mess_desc =
         getTermLabel("FOR_PO_LINE", 16) + ": " + string(pod_line) + " " +
         getTermLabel("CUMULATIVE_ID", 9) + ": " + ip_wo_id + " " +
         getTermLabel("WORK_ORDER_OPERATION", 4) + ": " + string(ip_wo_op).

      if lotserials_req then do:
         {pxmsg.i &MSGNUM=1119 &ERRORLEVEL=3 &MSGARG1=mess_desc}
         /* LOT/SERIAL NUMBER REQUIRED */
      end.
      else do:
         {pxmsg.i &MSGNUM=1989 &ERRORLEVEL=4 &MSGARG1=mess_desc}
         /* INVALID INVENTORY FOR BACKFLUSH */
      end.

      {pxmsg.i &MSGNUM=1988 &ERRORLEVEL=3}
      /* PLEASE BACKFLUSH COMPONENTS MANUALLY */
   end.
   else do:
      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled(ip_wo_id, ip_wo_op,
         OUTPUT_QUEUE)
      then do:
         run get_poline_porvis_wip_lots_from_user
            in h_wiplottrace_procs
            (
            input pod_nbr,
            input pod_line,
            input ip_wo_id,
            input ip_wo_op,
            input pod_qty_chg,
            input pod_um_conv * pod_rum_conv,
            input pod_rum,
            input ip_move,
            input wo_site,
            input po_vend,
            input '',
            output op_undo_all
            ) .
      end. /* if is_wiplottrace_enabled */
   end.
END PROCEDURE.
